package com.phicomm.view;

import java.util.zip.Inflater;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

import com.phicomm.appmanager.AppManagerActivity;
import com.phicomm.mobilesecurity.R;

public class SecurityNotification {
	
	private Notification mNotification;
	private NotificationManager mNotificationManager;
	private Context mContext;
	private RemoteViews mRemoteViews;
	private int mRemindValue;
	private int mTotalTraffic;
	private int mMonthTraffic;
	private static final int PERMANENT_NOTIFICATION_ID = 0x1101;
	private Inflater mInflater;
	
	public SecurityNotification(Context context){
		this.mContext = context;
		mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_panel);
		mNotification = new Notification.Builder(context).setSmallIcon(R.drawable.sym_def_app_icon).setContent(mRemoteViews).build();
		mNotification.flags = Notification.FLAG_ONGOING_EVENT;
		mNotificationManager = (NotificationManager) (context.getSystemService(Context.NOTIFICATION_SERVICE));
		initAction();
	}
	
	private void initAction() {
		Intent intent = new Intent(mContext, AppManagerActivity.class);
		setViewAction(R.id.tv_score, PendingIntent.getActivity(mContext, 0, intent, 0));
	}
	
	public SecurityNotification setDayTraffic(int daytraffic){
		mRemoteViews.setTextViewText(R.id.tv_day_traffic, daytraffic+"");
		return this;
	}
	
	public SecurityNotification setMonthTraffic(int monthTraffic){
		this.mMonthTraffic = monthTraffic;
		mRemoteViews.setTextViewText(R.id.tv_month_traffic, monthTraffic+"");
		mRemoteViews.setTextViewText(R.id.tv_remainder_traffic, mTotalTraffic-monthTraffic+"");
		mRemoteViews.setProgressBar(R.id.pb_traffic, mTotalTraffic , monthTraffic, false);
		return this;
	}
	
	public SecurityNotification setTotalTraffic(int value){
		this.mTotalTraffic = value;
		mRemoteViews.setTextViewText(R.id.tv_remainder_traffic, mTotalTraffic-mMonthTraffic+"");
		mRemoteViews.setProgressBar(R.id.pb_traffic, mTotalTraffic , mMonthTraffic, false);
		return this;
	}
	
	public SecurityNotification setInterceptMsg(String interceptMsg){
		mRemoteViews.setTextViewText(R.id.tv_intercept_msg, interceptMsg);
		return this;
	}
	
	public SecurityNotification setViewAction(int viewId, PendingIntent pIntent) {
		mRemoteViews.setOnClickPendingIntent(viewId, pIntent);
		return this;
	}
	
	public SecurityNotification setInterceptCall(String interceptCall){
		mRemoteViews.setTextViewText(R.id.tv_intercept_call, interceptCall);
		return this;
	}
	
	public SecurityNotification setPrivateMsg(String privateMsg){
		mRemoteViews.setTextViewText(R.id.tv_private_msg, privateMsg);
		return this;
	}
	
	public SecurityNotification setPrivateCall(String privateCall){
		mRemoteViews.setTextViewText(R.id.tv_private_call, privateCall);
		return this;
	}
	
	public SecurityNotification setScore(String score){
		mRemoteViews.setTextViewText(R.id.tv_score, score);
		return this;
	}
	
	public SecurityNotification setTrafficRemindsValue(int value){
		this.mRemindValue = value;
		return this;
	}
	
	public SecurityNotification setAction(Intent intent){
		mNotification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
		return this;
	}
	
	public SecurityNotification setScollAction(){
//		mRemoteViews.setOnClickFillInIntent(R.id.tv_score, fillInIntent)
		return this;
	}
	
	public void show(){
		mNotificationManager.notify(PERMANENT_NOTIFICATION_ID, mNotification);
	}
	
	public void cancle(){
		mNotificationManager.cancel(PERMANENT_NOTIFICATION_ID);
	}
	
}
